const wx2my = require('../../../wx2my');
const Behavior = require('../../../Behavior');
var base = require('./../../../config.js');

var app = getApp();
Page({
  data: {
    titel: ["全部", "待付款", "待确认", '待入住', '已完成', '已取消'],
    page: 1,
    order_list: [],
    imgUrl:''
  },
  onLoad: function (e) {
     console.log('订单列表')
    wx2my.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff'
    })
    app.getUserInfo(function (e) {
      console.log('订单列表的个人信息')
    });
    var t = e.activeIndex,
        a = e.index;
    console.log(a)
    this.setData({
      activeIndex: t,
      index: a,
      imgUrl: wx2my.getStorageSync(["imgUrl1"]).data,
    })
    this.refresh();
  },

  refresh: function (e) {
    my.showLoading({
      success: (res) => {
        
      },
    });
    var o = this,
        i = o.data.page,
        n = o.data.order_list,
        s = o.data.index;
    console.log(s);
    var t = wx2my.getStorageSync(["userInfo"]).data.uid,
        a = app.today_time();
        console.log('aaaaa：'+a)
    wx2my.newRequest({
      url: base.siteroot,
      data: {
        c:'entry',
        a:'wxapp',
        do:'MyOrder',
        m:'zh_jdgjb',
        user_id: t, //628
        page: i
      },
      success: (e) => {
        my.hideLoading();
        // console.log(e);
        // console.log('订单列表请求成功了。。。。。')
        console.log('列表长度：'+e.data.length);
        console.log(e.data)
         console.log('当前第几页:'+ this.data.page)

        if (0 < e.data.length) {
          o.setData({
            page: i + 1
        })
         
          n = n.concat(e.data);
          var t = [],
              a = [],
              d = [],
              w = [],
              q = [];

          

          for (var r in n)  console.log(n),n[r].arrival = n[r].arrival_time.slice(5, 7) + "月" + n[r].arrival_time.slice(8, 10) + "日",n[r].departure = n[r].departure_time.slice(5, 7) + "月" + n[r].departure_time.slice(8, 10) + "日", 1 == n[r].status && t.push(n[r]), 2 == n[r].status && a.push(n[r]), 2.5 == n[r].status && d.push(n[r]), 4 == n[r].status && w.push(n[r]), 5 == n[r].status && w.push(n[r]), 3 == n[r].status && q.push(n[r]), console.log(n[r].status);
         
          0 == s ? o.setData({
            order_list: n
          }) : 1 == s ? o.setData({
            order_list: t
          }) : 2 == s ? o.setData({
            order_list: a
          }) : 3 == s ? o.setData({
            order_list: d
          }) : 4 == s ? o.setData({
            order_list: w
          }) : 5 == s && o.setData({
            order_list: q
          });
        }
      },
      fail: (err) => {
        my.hideLoading();
        console.log(err)
      }
    })

    


  },

  tabClick1: function (e) {
    console.log(e.currentTarget.dataset.index);
    var o = this;
    o.setData({
      activeIndex: e.currentTarget.dataset.index
    });
  },

  tabClick: function (e) {
    console.log(e), this.setData({
      activeIndex: e.currentTarget.dataset.index,
      index: e.currentTarget.dataset.index,
      page: 1,
      order_list: []
    }), this.refresh();
  },

  order_info: function (e) {
    var t = e.currentTarget.dataset.id;
    console.log(t);
    wx2my.navigateTo({
      url: "orderinfo?id=" + t
    });
  },
  onReady: function () {},
  onShow: function () {
    this.setData({
      index: 0,
      activeIndex: 0,
      page: 1,
      order_list: []
    })
    this.refresh();
  },
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {
    console.log(this.data.page), 
    this.setData({
      page: 1,
      order_list: []
    })
    this.refresh()
    wx2my.stopPullDownRefresh();
  },
  onReachBottom: function () {
    console.log('加载。。。。。')
    this.refresh();
  },
  onShareAppMessage: function () {}
});